/** m2settings is a GUI to configure Maven 2 settings.xml 
 * 
 *  Copyright (C) 2007 Regis Decamps <decamps@users.sf.net>
 * 
 *  This file is part of m2settings.
 *
 *  m2settings is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version. 
 *
 *  Foobar is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *  or read it online http://www.gnu.org/licenses/gpl.txt
 *
 **/
/*
 * JFrameRepository.java
 *
 * Created on May 1, 2007, 9:44 PM
 */

package info.decamps.m2settings.swing;

import info.decamps.m2settings.beans.MyRepository;
import info.decamps.m2settings.documentation.DocumentationProvider;
import info.decamps.m2settings.model.AbstractRepositoryTableModel;
import info.decamps.m2settings.model.PluginRepositoriesTableModel;
import info.decamps.m2settings.model.PluginRepository;
import info.decamps.m2settings.model.RepositoriesTableModel;
import info.decamps.m2settings.model.Repository;
import info.decamps.m2settings.model.RepositoryPolicyType;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import javax.swing.DefaultComboBoxModel;
import org.apache.log4j.Logger;

/**
 *
 * @author  regis
 */
public class JFrameRepository extends javax.swing.JFrame {
    private MyRepository repo;
    private AbstractRepositoryTableModel model;
    private int index=-1;
    private DocumentationProvider documentation=DocumentationProvider.getInstance();
    private Logger log = Logger.getLogger(JFrameRepository.class);
    
    /** Creates new form JFrameRepository */
    public JFrameRepository(RepositoriesTableModel repositoriesModel, int index) {
        this.index=index;
        this.model=repositoriesModel;
        if (index >=0) {
            repo=new MyRepository(repositoriesModel.getRow(index));
            setTitle("Edit "+repositoriesModel.getElementName()+" "+repo.getId());
        } else {
            repo=new MyRepository((Repository)null);
            setTitle("Configure new "+repositoriesModel.getElementName());
        }
        initComponents();
        //TODO refresh spinner visibility
    }
    /** Creates new form JFrameRepository */
    public JFrameRepository(PluginRepositoriesTableModel repositoriesModel, int index) {
        this.index=index;
        this.model=repositoriesModel;
        if (index >=0) {
            repo=new MyRepository(repositoriesModel.getRow(index));
            setTitle("Edit "+repositoriesModel.getElementName()+" "+repo.getId());
        } else {
            repo=new MyRepository((PluginRepository)null);
            setTitle("Configure new "+repositoriesModel.getElementName());
        }
        initComponents();
        //TODO refresh spinner visibility
    }
    public JFrameRepository(RepositoriesTableModel repositoriesModel) {
        this(repositoriesModel,-1);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabelId = new javax.swing.JLabel();
        jLabelName = new javax.swing.JLabel();
        jLabelUrl = new javax.swing.JLabel();
        jLabelLayout = new javax.swing.JLabel();
        jComboBoxLayout = new javax.swing.JComboBox();
        jTextFieldId = new javax.swing.JTextField();
        jTextFieldName = new javax.swing.JTextField();
        jTextFieldUrl = new javax.swing.JTextField();
        jPanelReleases = new javax.swing.JPanel();
        jLabelReleases = new javax.swing.JLabel();
        jCheckBoxReleasesEnabled = new javax.swing.JCheckBox();
        jLabelReleasesUpdatePolicy = new javax.swing.JLabel();
        jComboBoxReleasesUpdatePolicy = new javax.swing.JComboBox();
        jLabelReleasesChecksumPolicy = new javax.swing.JLabel();
        jComboBoxReleasesChecksumPolicy = new javax.swing.JComboBox();
        jSpinnerReleasesUpdateInterval = new javax.swing.JSpinner();
        jPanelSnapshots = new javax.swing.JPanel();
        jLabelSnapshots = new javax.swing.JLabel();
        jCheckBoxSnapshotsEnabled = new javax.swing.JCheckBox();
        jLabelSnapshotsUpdatePolicy = new javax.swing.JLabel();
        jComboBoxSnapshotsUpdatePolicy = new javax.swing.JComboBox();
        jLabelSnapshotsChecksumPolicy = new javax.swing.JLabel();
        jComboBoxSnapshotsChecksumPolicy = new javax.swing.JComboBox();
        jSpinnerSnapshotsUpdateInterval = new javax.swing.JSpinner();
        jButtonOK = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jLabelId.setText("id");

        jLabelName.setText("name");

        jLabelUrl.setText("URL");

        jLabelLayout.setText("layout");

        jComboBoxLayout.setModel(new DefaultComboBoxModel(MyRepository.LAYOUT));
        jComboBoxLayout.setToolTipText("The type of layout this repository uses for locating and storing artifacts - can be \"legacy\" or \"default\".");

        jTextFieldId.setText(repo.getId());
        jTextFieldId.setToolTipText(documentation.getDescription("/Repository/id"));

        jTextFieldName.setText(repo.getName());
        jTextFieldName.setToolTipText(documentation.getDescription("/Repository/name"));

        jTextFieldUrl.setText(repo.getUrl());
        jTextFieldUrl.setToolTipText(documentation.getDescription("/Repository/url"));

        jPanelReleases.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanelReleases.setToolTipText("How to handle downloading of releases from this repository");
        jLabelReleases.setText("Releases");

        jCheckBoxReleasesEnabled.setSelected(repo.getReleasesEnabled());
        jCheckBoxReleasesEnabled.setText("enabled");
        jCheckBoxReleasesEnabled.setToolTipText(documentation.getDescription("/RepositoryPolicy/enabled"));
        jCheckBoxReleasesEnabled.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxReleasesEnabled.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jLabelReleasesUpdatePolicy.setText("update policy");
        jLabelReleasesUpdatePolicy.setToolTipText("The frequency for downloading updates - can be \"always\", \"daily\" (default), \"interval:XXX\" (in minutes) or \"never\" (only if it doesn't exist locally).");

        jComboBoxReleasesUpdatePolicy.setModel(new javax.swing.DefaultComboBoxModel(MyRepository.UPDATE_POLICIES));
        jComboBoxReleasesUpdatePolicy.setToolTipText(documentation.getDescription("/RepositoryPolicy/updatePolicy"));
        jComboBoxReleasesUpdatePolicy.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxReleasesUpdatePolicyItemStateChanged(evt);
            }
        });
        jComboBoxReleasesUpdatePolicy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxReleasesUpdatePolicyActionPerformed(evt);
            }
        });

        jLabelReleasesChecksumPolicy.setText("checksum policy");

        jComboBoxReleasesChecksumPolicy.setModel(new DefaultComboBoxModel(MyRepository.CHECKSUM_POLICY));
        jComboBoxReleasesChecksumPolicy.setToolTipText(documentation.getDescription("/RepositoryPolicy/checksumPolicy"));

        jSpinnerReleasesUpdateInterval.setToolTipText("interval in minutes");
        jSpinnerReleasesUpdateInterval.setValue(repo.getReleasesUpdateInterval());

        org.jdesktop.layout.GroupLayout jPanelReleasesLayout = new org.jdesktop.layout.GroupLayout(jPanelReleases);
        jPanelReleases.setLayout(jPanelReleasesLayout);
        jPanelReleasesLayout.setHorizontalGroup(
            jPanelReleasesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelReleasesLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelReleasesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanelReleasesLayout.createSequentialGroup()
                        .add(jLabelReleasesUpdatePolicy)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jComboBoxReleasesUpdatePolicy, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jSpinnerReleasesUpdateInterval, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE))
                    .add(jPanelReleasesLayout.createSequentialGroup()
                        .add(jLabelReleases)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 190, Short.MAX_VALUE)
                        .add(jCheckBoxReleasesEnabled))
                    .add(jPanelReleasesLayout.createSequentialGroup()
                        .add(jLabelReleasesChecksumPolicy)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jComboBoxReleasesChecksumPolicy, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanelReleasesLayout.setVerticalGroup(
            jPanelReleasesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelReleasesLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelReleasesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelReleases)
                    .add(jCheckBoxReleasesEnabled))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelReleasesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelReleasesUpdatePolicy)
                    .add(jComboBoxReleasesUpdatePolicy, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jSpinnerReleasesUpdateInterval, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelReleasesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelReleasesChecksumPolicy)
                    .add(jComboBoxReleasesChecksumPolicy, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jPanelSnapshots.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanelSnapshots.setToolTipText("How to handle downloading of snapshots from this repository");
        jLabelSnapshots.setText("Snapshots");

        jCheckBoxSnapshotsEnabled.setText("enabled");
        jCheckBoxSnapshotsEnabled.setToolTipText(documentation.getDescription("/RepositoryPolicy/enabled"));
        jCheckBoxSnapshotsEnabled.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxSnapshotsEnabled.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jLabelSnapshotsUpdatePolicy.setText("update policy");
        jLabelSnapshotsUpdatePolicy.setToolTipText("The frequency for downloading updates - can be \"always\", \"daily\" (default), \"interval:XXX\" (in minutes) or \"never\" (only if it doesn't exist locally).");

        jComboBoxSnapshotsUpdatePolicy.setModel(new javax.swing.DefaultComboBoxModel(MyRepository.UPDATE_POLICIES));
        jComboBoxSnapshotsUpdatePolicy.setToolTipText(documentation.getDescription("/RepositoryPolicy/updatePolicy"));
        jComboBoxSnapshotsUpdatePolicy.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBoxSnapshotsUpdatePolicyItemStateChanged(evt);
            }
        });

        jLabelSnapshotsChecksumPolicy.setText("checksum policy");

        jComboBoxSnapshotsChecksumPolicy.setModel(new DefaultComboBoxModel(MyRepository.CHECKSUM_POLICY));
        jComboBoxSnapshotsChecksumPolicy.setToolTipText(documentation.getDescription("/RepositoryPolicy/checksumPolicy"));

        jSpinnerSnapshotsUpdateInterval.setToolTipText("interval in minutes");

        org.jdesktop.layout.GroupLayout jPanelSnapshotsLayout = new org.jdesktop.layout.GroupLayout(jPanelSnapshots);
        jPanelSnapshots.setLayout(jPanelSnapshotsLayout);
        jPanelSnapshotsLayout.setHorizontalGroup(
            jPanelSnapshotsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelSnapshotsLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelSnapshotsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanelSnapshotsLayout.createSequentialGroup()
                        .add(jLabelSnapshotsUpdatePolicy)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jComboBoxSnapshotsUpdatePolicy, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jSpinnerSnapshotsUpdateInterval, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE))
                    .add(jPanelSnapshotsLayout.createSequentialGroup()
                        .add(jLabelSnapshots)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 179, Short.MAX_VALUE)
                        .add(jCheckBoxSnapshotsEnabled))
                    .add(jPanelSnapshotsLayout.createSequentialGroup()
                        .add(jLabelSnapshotsChecksumPolicy)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jComboBoxSnapshotsChecksumPolicy, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanelSnapshotsLayout.setVerticalGroup(
            jPanelSnapshotsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanelSnapshotsLayout.createSequentialGroup()
                .addContainerGap()
                .add(jPanelSnapshotsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelSnapshots)
                    .add(jCheckBoxSnapshotsEnabled))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelSnapshotsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelSnapshotsUpdatePolicy)
                    .add(jComboBoxSnapshotsUpdatePolicy, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jSpinnerSnapshotsUpdateInterval, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelSnapshotsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelSnapshotsChecksumPolicy)
                    .add(jComboBoxSnapshotsChecksumPolicy, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jButtonOK.setText("OK");
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        jButtonCancel.setText("Cancel");
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanelReleases, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(jLabelId)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextFieldId, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabelLayout)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jComboBoxLayout, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(jLabelName)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextFieldName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(jLabelUrl)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextFieldUrl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 302, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jButtonCancel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 210, Short.MAX_VALUE)
                        .add(jButtonOK))
                    .add(jPanelSnapshots, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelId)
                    .add(jComboBoxLayout, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabelLayout)
                    .add(jTextFieldId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelName)
                    .add(jTextFieldName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelUrl)
                    .add(jTextFieldUrl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelReleases, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanelSnapshots, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 25, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonOK)
                    .add(jButtonCancel))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
        repo.setId(jTextFieldId.getText());
        repo.setLayout(MyRepository.LAYOUT[jComboBoxLayout.getSelectedIndex()]);
        repo.setName(jTextFieldName.getText());
        repo.setReleasesChecksumPolicy(MyRepository.CHECKSUM_POLICY[jComboBoxReleasesChecksumPolicy.getSelectedIndex()]);
        repo.setReleasesEnabled(jCheckBoxReleasesEnabled.isSelected());
        repo.setReleasesUpdate(MyRepository.UPDATE_POLICIES[jComboBoxReleasesUpdatePolicy.getSelectedIndex()],
                ((Integer)jSpinnerReleasesUpdateInterval.getValue()).intValue());
        repo.setUrl(jTextFieldUrl.getText());
        if(index<0) {
            RepositoryPolicyType r=repo.getRepository();
            log.debug("model of class "+model.getClass());
            log.debug("new repo added of type "+r.getClass());
            if (r.getClass()==Repository.class) {
                ((RepositoriesTableModel)model).addRow((Repository)r);
            } else if (r.getClass()==PluginRepository.class) {
                ((PluginRepositoriesTableModel)model).addRow((PluginRepository)r);
            }
        } else {
            log.debug("Repository configuration changed");
            model.fireChange(index);
        }
        dispose();
    }//GEN-LAST:event_jButtonOKActionPerformed
    
    private void jComboBoxReleasesUpdatePolicyItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxReleasesUpdatePolicyItemStateChanged
        if (jComboBoxReleasesUpdatePolicy.getSelectedIndex()==2) { //interval
            jSpinnerReleasesUpdateInterval.setVisible(true);
        } else {
            jSpinnerReleasesUpdateInterval.setVisible(false);
        }
    }//GEN-LAST:event_jComboBoxReleasesUpdatePolicyItemStateChanged
    
    private void jComboBoxSnapshotsUpdatePolicyItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBoxSnapshotsUpdatePolicyItemStateChanged
        
        if (jComboBoxSnapshotsUpdatePolicy.getSelectedIndex()==2) {//interval
            jSpinnerSnapshotsUpdateInterval.setVisible(true);
        } else {
            jSpinnerSnapshotsUpdateInterval.setVisible(false);
        }
    }//GEN-LAST:event_jComboBoxSnapshotsUpdatePolicyItemStateChanged
    
    private void jComboBoxReleasesUpdatePolicyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxReleasesUpdatePolicyActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxReleasesUpdatePolicyActionPerformed
    
    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        dispose();
    }//GEN-LAST:event_jButtonCancelActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JCheckBox jCheckBoxReleasesEnabled;
    private javax.swing.JCheckBox jCheckBoxSnapshotsEnabled;
    private javax.swing.JComboBox jComboBoxLayout;
    private javax.swing.JComboBox jComboBoxReleasesChecksumPolicy;
    private javax.swing.JComboBox jComboBoxReleasesUpdatePolicy;
    private javax.swing.JComboBox jComboBoxSnapshotsChecksumPolicy;
    private javax.swing.JComboBox jComboBoxSnapshotsUpdatePolicy;
    private javax.swing.JLabel jLabelId;
    private javax.swing.JLabel jLabelLayout;
    private javax.swing.JLabel jLabelName;
    private javax.swing.JLabel jLabelReleases;
    private javax.swing.JLabel jLabelReleasesChecksumPolicy;
    private javax.swing.JLabel jLabelReleasesUpdatePolicy;
    private javax.swing.JLabel jLabelSnapshots;
    private javax.swing.JLabel jLabelSnapshotsChecksumPolicy;
    private javax.swing.JLabel jLabelSnapshotsUpdatePolicy;
    private javax.swing.JLabel jLabelUrl;
    private javax.swing.JPanel jPanelReleases;
    private javax.swing.JPanel jPanelSnapshots;
    private javax.swing.JSpinner jSpinnerReleasesUpdateInterval;
    private javax.swing.JSpinner jSpinnerSnapshotsUpdateInterval;
    private javax.swing.JTextField jTextFieldId;
    private javax.swing.JTextField jTextFieldName;
    private javax.swing.JTextField jTextFieldUrl;
    // End of variables declaration//GEN-END:variables
    
}
